/* GUI CONVERTED from windowx.i (converter v1.76) Fri Mar  1 10:07:03 2002 */
/* windowx.i - Extended Scrolling Window, 1 Table, 1 or 2 Indexes & criteria */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.20 $                                                         */
/*V8:ConvertMode=Maintenance                                                 */
/* REVISION: 7.3    CREATED:       12/18/95         BY: jzs *G1GR*           */
/* REVISION: 7.3    CREATED:       12/18/95         BY: jzs *G1GS*           */
/* REVISION: 7.3    CREATED:       03/18/96         BY: qzl *G1QV*           */
/* REVISION: 8.5    LAST MODIFIED: 04/11/96         BY: *J04C* Sue Poland    */
/* REVISION: 8.5    LAST MODIFIED: 04/11/96         BY: *J04C* Markus Barone */
/* REVISION: 8.5    LAST MODIFIED: 01/07/97         BY: *G2JM* Tamra MacInnis*/
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98         BY: *L007* A. Rahane     */
/* REVISION: 8.6E   LAST MODIFIED: 10/04/98         BY: *J314* Alfred Tan    */
/* REVISION: 8.6E   LAST MODIFIED: 10/14/98         BY: *L0C2* Alfred Tan    */
/* REVISION: 9.1      LAST MODIFIED: 03/23/00       BY: *N08T* D.Taylor      */
/* REVISION: 9.1      LAST MODIFIED: 04/13/00       BY: *N08H* Veena Lad     */
/* REVISION: 9.1      LAST MODIFIED: 05/12/00       BY: *N091* Rajesh Thomas */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00       BY: *N0KC* myb           */
/* Revision: 1.17    BY: Katie Hilbert  DATE: 04/04/01 ECO: *P008*           */
/* Revision: 1.18    BY: Murali Ayyagari  DATE: 07/20/01 ECO: *N10H*   */
/* $Revision: 1.20 $   BY: John Pison  DATE: 02/08/02 ECO: *N18V*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*! **************************************************************************

   Single Table, can pivot on 2 INDEXES, allows criteria & multiple-selection.
   Can be used for single index by passing in the same index for both. Can
   even pass back a non-index-lead-field. (See TRICK below in Assumptions).

   One of the 2 system global recid variables must be set (pass in the one
   you want as &recid-var), but the returning of the selected value to the
   current frame field can be enabled or disables with &return. If it is
   disabled and the value returning is done by the calling SW program, be
   sure to mimic the exact logic done in this include. MFG/PRO V8 must be
   handled correctly!

   Beg-of-File and End-of-File beeps are given when scrolling of the
   ends of the table.

Arguments:        Descriptions:                        Examples:

  {&file}       = Table name (filename)              : pt_mstr
  {&display}    = List of fields to display in frame : "pt_part pt_desc1"
                  Must include indexed fields
  {&index-fld1} = Indexed field #1 name
  {&use-index1} = Indexed field #1 use-index phrase  : "use-index pt_part"
  {&index-fld2} = Indexed field #2 name
  {&use-index2} = Indexed field #2 use-index phrase  : "use-index pt_desc"
  {&frametitle} = Frame title w/ bordering spaces    : """ The A Parts """
  {&framephrase}= Extra frame phrase parameters      : "no-label width 80"
                  (optional)

  {&where}      = Additional criteria w/ WHERE       : "where pt_abc = ""A"" "
  {&and}        = Additional criteria w/ AND         : "and  pt_abc = ""A"" "
                  (optional, but both or neither)

  {&return}     = Return selection in frame-value    : yes

  {&recid-var}  = Variable to return the recid in    : global_recid
                  global_recid, or window_recid

  {&run-help}   = When set to "YES" the HELP key will
                  transfer control to applhelp.p, otherwise
                  the HELP key will cause a return.  SW
                  programs that are called from applhelp.p
                  (i.e., the user F2's to get to them) must
                  leave this field blank, so that they will
                  return to applhelp.p.  SW programs that are
                  called directly by other application
                  programs must set this value to "YES" so
                  that applhelp.p will properly display
                  field/procedure help.

  {&nogetframetitle} = Optional. Not to use the getFrameTitle function.
                       This will be useful when the frametitle is already
                       translated.

These arguments enable multiple-selection via a tag variable in the record:

  {&tag-var}    = Field to toggle on multi-select,   : pt_qad15
                  must be in &display; or use
                  "wtemp3" => no multiple selection
  {&tag-val1}   = Field-value for first toggle state : yes
  {&tag-val2}   = Field-value for second state       : no
                  These two parameters allow this
                  code to work with tag variables
                  that are logicals (yes/no), or
                  characters ("""","*"). For no
                  multiple selection &tag-var=wtemp3
                  use: """"  for both &tag-vals.
  {&tag-all}    = Allow selecting all via F6 key.   : yes
                  This feature does not mark all
                  record's tag-var, it sets the
                  "selectall" variable to yes/no.

Assumptions:
1.  Indexed fields are the highest order variant field of the Index-key,
    that is it is either the highest order field in the Index-key
    or all higher order index fields in the Index-key will not vary
    due to the additional search criteria. Unless below trick is used.

TRICK !!!
   When the use-index1/2 parameters are the same the second index pivot is
   used. This allows you to vary the 2 index-flds. index-fld1 must be the
   field to return, but if it is not the lead field in any index, this trick
   allows you to put the lead-field of the index in index-fld2 and searching
   works on that index only, while the other field is returned.

2. Select criteria MUST be used with extreme caution when using 2 indexes.
   When pivoting to the other index time-consuming serial reads will result
   if the criteria is not the high-order component of the 2nd index.

3. {wndvar1/2.i} has been included in the parent source file for defines.

4. When using record tagging (multiple-selection) the local variable
   "selectall" is used, if the scrolling window program including this
   file need to pass this flag back to a parent program, it must use
   another shared variable such as "select_all".
****************************************************************************/
/*Tried using mfmsg{} but it pushes Parent-of-Help field to foreground        */

/* TO DEFINE VARIABLE GLOBAL_GBLMGR_HANDLE          */
{pxgblmgr.i}

if window_row = 0 then window_row = 6.
if window_down = 0 then window_down = 8.

FORM /*GUI*/ 
   /* Don't put &display list here, so substr() @ fld works */
with frame w centered row window_row window_down down
   scroll 1 overlay no-validate  {&framephrase}
   attr-space title color normal
   &IF DEFINED(nogetframetitle) <> 2 &THEN
       getframetitle({&frametitle},60) BGCOLOR 8 /*GUI*/.

   &ELSE
       {&frametitle}.
   &ENDIF

/* SET EXTERNALIZED LABELS. */
setFrameLabels(frame w:handle).

/* If there are no records, warn and readkey to call field help via applhelp */

assign {&recid-var}  = ?.
hide message no-pause.
find first {&file} {&where} no-lock no-error.
if not available {&file} then do:
   /* THERE ARE NO RECORDS IN FILE */
   {pxmsg.i &MSGNUM=2767 &ERRORLEVEL=1
            &MSGARG1=""{&file}""
            &MSGARG2=""""
            &MSGARG3=""""}
   pause.
   return.
end.

/* Prepare local variables and status line for entry to keystroke loop */

/* First time through, start sw_drop_in = yes */
sw_drop_in = yes.

if {&return} then
   frame_val_save = frame-value.

status input off.
assign sw_no_pivot = "{&use-index1}" = "{&use-index2}".
if "{&tag-var}" = "wtemp3" then do:        /* No Multiple-Selection */
   if sw_no_pivot then
      status default stline[4].      /* Standard 1-index no pivot */
   else
      status default stline[5].      /* Standard 2-index pivot */

   partial_ixval = "".
end.
else do:                                 /* Multi-selection enabled */
   if {&tag-all} then        /* Allow F6 = All */
      if sw_no_pivot then
         status default stline[8].   /* 1 Index w/ All */
      else
         status default stline[9].   /* 2 Indexes w/ All */
   else                     /* Don't Allow F6 = All */
   if "{&index-fld1}" = "{&index-fld2}" then
      status default stline[6].   /* 1 Index w/o All */
   else
      status default stline[7].   /* 2 Indexes w/o All */

   partial_ixval = "".
end.

partial_ixlen = length(partial_ixval).
do while partial_ixlen > 0
      and substring(partial_ixval,partial_ixlen,1) = " ":
   partial_ixlen = partial_ixlen - 1.
end.
partial_ixval = substring(partial_ixval,1,partial_ixlen).

field_nbr = 0.             /* Set to 0 to drop into Key-Stroke loop */
if partial_ixlen = 0 then  /* Initialize variable for Beg-of-File */
   sw_at_top = yes.
else
   sw_at_top = no.

/* Seek to first record to prepare for first frame paint */

find first {&file} where {&index-fld1} >= partial_ixval
   {&and} {&use-index1} no-lock no-error.
if not available {&file} then
   find last {&file} where {&index-fld1} <= partial_ixval
   {&and} {&use-index1} no-lock no-error.

/* MAIN key-stroke loop */
do while
      sw_drop_in or    /* used to drop into keystroke loop */
      field_nbr = 0 or /* used to drop into loop for first key */
      lastkey = keycode("BACKSPACE") or (lastkey >= 32 and lastkey <= 255)
      or lastkey = keycode("TAB")
      or lastkey = keycode("CTRL-U")
      or lastkey = keycode("F9")
      or lastkey = keycode("CURSOR-UP")   /* Catches CTRL-K */
      or lastkey = keycode("F10")
      or lastkey = keycode("CURSOR-DOWN") /* Catches CTRL-J */
      or lastkey = keycode("CURSOR-LEFT")
      or lastkey = keycode("CURSOR-RIGHT")
      or lastkey = keycode("F7")
      or lastkey = keycode("CTRL-R")
      or lastkey = keycode("PAGE-UP")
      or lastkey = keycode("F8")
      or lastkey = keycode("CTRL-Z")
      or lastkey = keycode("PAGE-DOWN")
      or lastkey = keycode("F6")
      or lastkey = keycode("CTRL-P")
      or lastkey = keycode("RETURN")
   with frame w:

   /* When field_nbr is 0 we have just dropped into the loop. The TRICK below
   of setting to the second pivot when both indexes are the same allows you
   to use only one index where the field to return is not the lead field.   */

   if field_nbr = 0 then                 /* To start things off */
      if sw_no_pivot then
         field_nbr = 2.  /* Use 2nd pivot when both */
      else
         field_nbr = 1.  /* indexes are the same. */
   sw_drop_in = no.

   if repaint then do:         /* REPAINT FRAME FROM CURRENT RECORD */
      repaint = no.
      sw_at_end = no.
      clear frame w all no-pause.
      ixlastline = 0.
      DispLoop:
      do while available {&file} with frame w:
         assign
            ixlastline = ixlastline + 1
            ix1array[ixlastline] = {&index-fld1}
            ix2array[ixlastline] = {&index-fld2}
            recidarray[ixlastline] = recid({&file}).
         display
                                space(1)   
            {&display}
                                space(1)   
            .
         /* Get next record even at end of frame to check EOF */
         if field_nbr = 1 then
            find next {&file} {&where} {&use-index1} no-lock no-error.
         else
            find next {&file} {&where} {&use-index2} no-lock no-error.
         if not available {&file} then
            sw_at_end = yes.
         else
         if frame-line < frame-down then
            down 1.
         else
            leave DispLoop.
      end.

      if up_jump = 1 then
         up ixlastline - 1.      /* Move cursor to top of frame */
      else
      if up_jump = 2 then
         if {gpiswrap.i} then
            up (ixlastline - 1).
         else
            up (ixlastline - 1) / 2. /* Move cursor to middle of frame */
      else do:
         up ixlastline - j.      /* Move cursor back to current spot */
         partial_ixval = "".     /* and reset incremental search */
         partial_ixlen = 0.      /* on Tab-Pivot */
      end.

      if field_nbr = 1 then do:
         color prompt-for messages {&index-fld1}.
         partial_ixval = substring(ix1array[1] + spcs,1,partial_ixlen).
      end.
      else do:
         color prompt-for messages {&index-fld2}.
         partial_ixval = substring(ix2array[1] + spcs,1,partial_ixlen).
      end.
   end. /* repainting frame */

   prompt-for {&index-fld1} when (field_nbr = 1) /* GET A KEYSTROKE */
      {&index-fld2} when (field_nbr = 2)
      with frame w
   editing:
      do i = 1 to partial_ixlen:
         apply keycode("CURSOR-RIGHT").
      end.
      readkey.
      leave.
   end. /* Get a keystroke */
   assign wtemp3 = input {&index-fld1}.  /* to stop compile warning */
   assign wtemp3 = input {&index-fld2}.

   /*When this is running in a wrapper (i.e. Desktop) we need
     the HELP key to work regardless of what {&run-help} is set to*/
   if {gpiswrap.i} then do:
      if keyfunction(lastkey) = "HELP" then do:
         apply lastkey.
         sw_drop_in = yes.
         next.
      end.
   end.

   /* ADDED HELP FUNCTION, WHEN &RUN-HELP = "YES" */
   if keyfunction(lastkey) = "HELP"
      and "{&run-help}" = "yes" then do:
      apply lastkey. /* Jump to applhelp.p */
      /* GET A KEYSTROKE */
      prompt-for {&index-fld1} when (field_nbr = 1)
         {&index-fld2} when (field_nbr = 2)
         with frame w
      editing:
         do i = 1 to partial_ixlen:
            apply keycode("CURSOR-RIGHT").
         end.
         readkey.
         leave.
      end. /* Get a keystroke editing */
      sw_drop_in = yes.
      next.          /* Continue on in this SW program */
   end.

   if lastkey = keycode("F5") then do: 
       apply lastkey.
       leave.
   end.

   if lastkey = keycode("RETURN") and "{&tag-var}" = "wtemp3" then
      leave.

   if lastkey = keycode("F6") or lastkey = keycode("CTRL-P") then do:
      if "{&tag-var}" <> "wtemp3" and {&tag-all} then do:
         message getTermLabel("SELECT_ALL",15) + "." update  selectall.
         if selectall then
            leave.
         else next.
      end.
      else
         apply lastkey.
   end.

   if field_nbr = 1 then do: /* BROWSE ON FIRST INDEXED FIELD ------*/
      /* (one indent level missing) */
      if lastkey = keycode("BACKSPACE") or
         lastkey = keycode("CURSOR-LEFT")
      then do:
         if partial_ixlen > 0 then partial_ixlen = partial_ixlen - 1.
         partial_ixval = substring(partial_ixval + spcs,1,partial_ixlen).
      end.

      else if lastkey = keycode("CURSOR-RIGHT") then do:
         if length(ix1array[frame-line]) > partial_ixlen then
         assign
            partial_ixlen = partial_ixlen + 1
            partial_ixval =
               substring(ix1array[frame-line] + spcs,1,partial_ixlen).
      end.

      else if lastkey >= 32 and lastkey <= 255 then do:
         partial_ixval = partial_ixval + chr(lastkey).
         partial_ixlen = partial_ixlen + 1.
         if partial_ixval > ix1array[ixlastline]
            or partial_ixval < ix1array[1]       /* Must move off frame */
         then do:
            find first {&file} where {&index-fld1} >= partial_ixval
               {&and} {&use-index1} no-lock no-error.
            if available {&file} then do:
               if {&index-fld1} = ix1array[1] then do:
                  up frame-line - 1.
                  color prompt-for messages {&index-fld1}.
                  partial_ixval =
                  substring(ix1array[1] + spcs,1,partial_ixlen).
               end.
               else
               assign
                  up_jump = 1 /* Top of list */
                  repaint = yes
                  sw_at_top = no.
            end.
            else do:
               if partial_ixlen > 1 then
                  partial_ixlen = partial_ixlen - 1.
               partial_ixval =
                  substring(partial_ixval + spcs,1,partial_ixlen).
            end.
         end.
         else do: /* LOCATE FIRST SCREEN ELEMENT >= partial_ixval */
            i = 1.
            do while ix1array[i] < partial_ixval:
               i = i + 1.
            end.
            up frame-line - i.  /* Negative value here is down */
            color prompt-for messages {&index-fld1}.
            partial_ixval = substring(ix1array[i] + spcs,1,partial_ixlen).
         end.
      end.

      else
      if lastkey = keycode("F7")
         or lastkey = keycode("CTRL-R")
         or lastkey = keycode("PAGE-UP")      /* PAGE BACKWARD */
      then do:
         if sw_at_top then do:
            bell.
            next.
         end.
         find {&file} where recid({&file}) = recidarray[1]
            no-lock no-error.
         do i = 1 to frame-down - 1 while available {&file}:
            find prev {&file} {&where} {&use-index1} no-lock no-error.
         end.
         if not available {&file} then do:
            find first {&file} {&where} {&use-index1} no-lock no-error.
            sw_at_top = yes.
         end.
         up_jump = 2. /* Mid-List on page scrolls */
         repaint = yes.
      end.

      else
      if lastkey = keycode("F8")
         or lastkey = keycode("CTRL-Z")
         or lastkey = keycode("PAGE-DOWN") /* PAGE FORWARD */
      then do:
         if sw_at_end then do:
            bell.
            next.
         end.
         find {&file} where recid({&file}) = recidarray[ixlastline]
            no-lock no-error.
         assign
            up_jump = 2 /* Mid-List on page scrolls */
            repaint = yes
            sw_at_top = no.
      end.

      else
      if lastkey = keycode("CURSOR-UP") or lastkey = keycode("F9")
      then do:
         if frame-line = 1 then do:
            if sw_at_top then do:
               bell.
               next.
            end.
            find {&file} where recid({&file}) = recidarray[1]
               no-lock no-error.
            find prev {&file} {&where} {&use-index1} no-lock no-error.
            if available {&file} then
            assign
               up_jump = 1 /* Top of list */
               repaint = yes.
            else do:
               sw_at_top = yes.
               bell.
            end.
         end.
         else do:
            up 1.
            color prompt-for messages {&index-fld1}.
            partial_ixval =
               substring(ix1array[frame-line] + spcs,1,partial_ixlen).
         end.
      end.

      else
      if lastkey = keycode("CURSOR-DOWN")
         or lastkey = keycode("RETURN")
         or lastkey = keycode("F10")
      then do:

         if lastkey = keycode("RETURN") then do:
            /* Only TRUE if doing multiple-selection => mark this record */
            /* Notice localized LOCK right here */
            find {&file} where recid({&file}) = recidarray[frame-line]
               no-error.
            if available {&file} then do:
               if {&tag-var} = {&tag-val1} then
                  {&tag-var} = {&tag-val2}.
               else
                  {&tag-var} = {&tag-val1}.
               display {&display}.
               color prompt-for messages {&index-fld1}.
               release {&file}.
            end.
         end.

         if frame-line = ixlastline then do:
            if sw_at_end then do:
               bell.
               next.
            end.
            /* On last line in frame, get next record past last one in */
            /* frame, move up data by 1, and paint the new entry. */
            find {&file} where recid({&file}) = recidarray[ixlastline]
               no-lock no-error.
            find next {&file} {&where} {&use-index1} no-lock no-error.
            if available {&file} then do:
               down 1.
               sw_at_top = no.
               display {&display}.
               color prompt-for messages {&index-fld1}.
               do i = 1 to ixlastline:
                  assign
                     ix1array[i] = ix1array[i + 1]
                     ix2array[i] = ix2array[i + 1]
                     recidarray[i] = recidarray[i + 1].
               end.
               assign
                  ix1array[ixlastline] = {&index-fld1}
                  ix2array[ixlastline] = {&index-fld2}
                  recidarray[ixlastline] = recid({&file})
                  partial_ixval =
                  substring(ix1array[ixlastline] + spcs ,1,partial_ixlen).
            end.
            else do:
               sw_at_end = yes.
               bell.
            end.
         end.
         else do: /* Can just move cursor down one line */
            down 1.
            color prompt-for messages {&index-fld1}.
            partial_ixval =
            substring(ix1array[frame-line] + spcs,1,partial_ixlen).
         end.
      end.

      else
      if (lastkey = keycode("TAB")
         or lastkey = keycode("CTRL-U"))
         and (not sw_no_pivot)
      then do:
         /* Pivot screen to second indexed field */
         assign
            field_nbr = 2
            i = frame-line
            j = 1.
         find {&file} where recid({&file}) = recidarray[i]
            no-lock no-error.
         do while i > 1 and available {&file}:
            find prev {&file} {&where} {&use-index2} no-lock no-error.
            i = i - 1.
            if available {&file} then j = j + 1.
         end.
         if not available {&file} then
            find first {&file} {&where} {&use-index2} no-lock no-error.
         assign
            up_jump = 3 /* Keep same frame line and record */
            repaint = yes
            sw_at_top = no
            sw_at_end = no.
      end.

   end.                               /* (one indent level missing) */
   else do: /* BROWSE ON THE SECOND FIELD --------------------------*/

      if lastkey = keycode("BACKSPACE") or
         lastkey = keycode("CURSOR-LEFT")
      then do:
         if partial_ixlen > 0 then partial_ixlen = partial_ixlen - 1.
         partial_ixval = substring(partial_ixval + spcs,1,partial_ixlen).
      end.

      else if lastkey = keycode("CURSOR-RIGHT") then do:
         if length(ix2array[frame-line]) > partial_ixlen then
         assign
            partial_ixlen = partial_ixlen + 1
            partial_ixval =
            substring(ix2array[frame-line] + spcs,1,partial_ixlen).
      end.

      else if lastkey >= 32 and lastkey <= 255 then do:
         partial_ixval = partial_ixval + chr(lastkey).
         partial_ixlen = partial_ixlen + 1.
         if partial_ixval > ix2array[ixlastline]
            or partial_ixval < ix2array[1]       /* Must move off frame */
         then do:
            find first {&file} where {&index-fld2} >= partial_ixval
               {&and} {&use-index2} no-lock no-error.
            if available {&file} then do:
               if {&index-fld2} = ix2array[1] then do:
                  up frame-line - 1.
                  color prompt-for messages {&index-fld2}.
                  partial_ixval =
                  substring(ix2array[1] + spcs,1,partial_ixlen).
               end.
               else
               assign
                  up_jump = 1 /* Top of list */
                  repaint = yes
                  sw_at_top = no.
            end.
            else do:
               if partial_ixlen > 1 then
                  partial_ixlen = partial_ixlen - 1.
               partial_ixval =
               substring(partial_ixval + spcs,1,partial_ixlen).
            end.
         end.
         else do: /* LOCATE FIRST SCREEN ELEMENT >= partial_ixval */
            i = 1.
            do while ix2array[i] < partial_ixval:
               i = i + 1.
            end.
            up frame-line - i.  /* Negative value here is down */
            color prompt-for messages {&index-fld2}.
            partial_ixval = substring(ix2array[i] + spcs,1,partial_ixlen).
         end.
      end.

      else
      if lastkey = keycode("F7")
         or lastkey = keycode("CTRL-R")
         or lastkey = keycode("PAGE-UP")      /* PAGE BACKWARD */
      then do:
         if sw_at_top then do:
            bell.
            next.
         end.
         find {&file} where recid({&file}) = recidarray[1]
            no-lock no-error.
         do i = 1 to frame-down - 1 while available {&file}:
            find prev {&file} {&where} {&use-index2} no-lock no-error.
         end.
         if not available {&file} then do:
            find first {&file} {&where} {&use-index1} no-lock no-error.
            sw_at_top = yes.
         end.
         up_jump = 2. /* Mid-List on page scrolls */
         repaint = yes.
      end.

      else
      if lastkey = keycode("F8")
         or lastkey = keycode("CTRL-Z")
         or lastkey = keycode("PAGE-DOWN") /* PAGE FORWARD */
      then do:
         if sw_at_end then do:
            bell.
            next.
         end.
         find {&file} where recid({&file}) = recidarray[ixlastline]
            no-lock no-error.
         assign
            up_jump = 2 /* Mid-List on page scrolls */
            repaint = yes
            sw_at_top = no.
      end.

      else
      if lastkey = keycode("CURSOR-UP") or lastkey = keycode("F9")
      then do:
         if frame-line = 1 then do:
            if sw_at_top then do:
               bell.
               next.
            end.
            find {&file} where recid({&file}) = recidarray[1]
               no-lock no-error.
            find prev {&file} {&where} {&use-index2} no-lock no-error.
            if available {&file} then
            assign
               up_jump = 1 /* Top of list */
               repaint = yes.
            else do:
               sw_at_top = yes.
               bell.
            end.
         end.
         else do:
            up 1.
            color prompt-for messages {&index-fld2}.
            partial_ixval =
            substring(ix2array[frame-line] + spcs,1,partial_ixlen).
         end.
      end.

      else
      if lastkey = keycode("CURSOR-DOWN")
         or lastkey = keycode("RETURN")
         or lastkey = keycode("F10")
      then do:
         if lastkey = keycode("RETURN") then do:
            /* Only TRUE if doing multiple-selection => mark this record */
            /* Notice localized LOCK right here */
            find {&file} where recid({&file}) = recidarray[frame-line]
               no-error.
            if available {&file} then do:
               if {&tag-var} = {&tag-val1} then
                  {&tag-var} = {&tag-val2}.
               else
                  {&tag-var} = {&tag-val1}.
               display {&display}.
               color prompt-for messages {&index-fld2}.
               release {&file}.
            end.
         end.

         if frame-line = ixlastline then do:
            if sw_at_end then do:
               bell.
               next.
            end.
            /* On last line in frame, get next record past last one in */
            /* frame, move up data by 1, and paint the new entry. */
            find {&file} where recid({&file}) = recidarray[ixlastline]
               no-lock no-error.
            find next {&file} {&where} {&use-index2} no-lock no-error.
            if available {&file} then do:
               down 1.
               sw_at_top = no.
               display {&display}.
               color prompt-for messages {&index-fld2}.
               do i = 1 to ixlastline:
                  ix1array[i] = ix1array[i + 1].
                  ix2array[i] = ix2array[i + 1].
                  recidarray[i] = recidarray[i + 1].
               end.
               assign
                  ix1array[ixlastline] = {&index-fld1}
                  ix2array[ixlastline] = {&index-fld2}
                  recidarray[ixlastline] = recid({&file})
                  partial_ixval =
                  substring(ix2array[ixlastline] + spcs,1,partial_ixlen).
            end.
            else do:
               sw_at_end = yes.
               bell.
            end.
         end.
         else do: /* Can just move cursor down one line */
            down 1.
            color prompt-for messages {&index-fld2}.
            partial_ixval =
            substring(ix2array[frame-line] + spcs,1,partial_ixlen).
         end.
      end.

      else
      if (lastkey = keycode("TAB")
         or lastkey = keycode("CTRL-U") )
         and (not sw_no_pivot)
      then do:
         /* Pivot screen to first indexed field */
         assign
            field_nbr = 1
            i = frame-line
            j = 1.
         find {&file} where recid({&file}) = recidarray[i]
            no-lock no-error.
         do while i > 1 and available {&file}:
            find prev {&file} {&where} {&use-index1} no-lock no-error.
            i = i - 1.
            if available {&file} then j = j + 1.
         end.
         if not available {&file} then
            find first {&file} {&where} {&use-index1} no-lock no-error.
         assign
            up_jump = 3 /* Keep same frame line and record */
            repaint = yes
            sw_at_top = no
            sw_at_end = no.
      end.

   end. /* BROWSE ON SECOND VS. FIRST FIELD -------------------------- */

end. /* Do while valid keystrokes (one ident level missing) jzs */

i = frame-line(w).
/*
hide frame w.
*/

if keyfunction(lastkey) = "GO" or lastkey = keycode("RETURN") then do:
   if {&return} then frame-value = ix1array[i].
   {&recid-var} = recidarray[i].
               if valid-handle(global-drill-handle) then
   global-drill-handle:screen-value = string(frame-value).   
end.
else do:
   if {&return} then frame-value = frame_val_save.
   {&recid-var} = ?.
               if valid-handle(global-drill-handle) then
   global-drill-handle:screen-value = frame_val_save.   
end.

/* End windowx.i */
